package com.powernode.work.controller;

import com.powernode.commons.utils.ResponseData;
import com.powernode.work.bean.ActivityBean;
import com.powernode.work.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("activity")
@Api(tags = "市场活动维护")
public class ActivityController {
    @Autowired
    private ActivityService service;


    @GetMapping
    @ApiOperation("分页显示所有的市场活动")
    public ResponseData page(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                             @RequestParam(required = false,defaultValue = "5")Integer pageSize,
                             ActivityBean activity){

        return service.pageList(pageNum,pageSize,activity);
    }

    @PostMapping
    @ApiOperation("添加活动")
    public ResponseData add(@RequestBody ActivityBean activity){
        return service.add(activity);
    }

    @PutMapping
    @ApiOperation("编辑活动")
    public ResponseData edit(@RequestBody ActivityBean activity){
        return service.modify(activity);
    }

    @DeleteMapping
    @ApiOperation("根据主键删除")
    public ResponseData delete(@ApiParam("主键,如果多个用逗号隔开") String ids){
        return service.remove(ids);
    }


    @GetMapping("getById")
    @ApiOperation("根据主键id查询市场活动的详情")
    public ResponseData getById(String id){
        return service.findById(id);
    }

    @GetMapping("getActivitysByClueId")
    @ApiOperation("根据线索id查询市场活动")
    public ResponseData getActivitysByClueId(String clueId){
        return  service.findActivitysByClueId(clueId);
    }


        @DeleteMapping("deleteClueActivity")
        @ApiOperation("解除线索市场活动的关联")
        public ResponseData deleteClueActivity(String clueId ,String activityId){
            return service.removeActivityClueByActivityIdAndClueId(clueId, activityId);
        }

@GetMapping("group")
    public ResponseData group(){
        return service.findCountGroup();
    }
}
